<script setup lang="ts">
import { useLayoutState } from '../../basic-layout/context'
import SubMenu from './sub-menu.vue'

const { theme, collapsed, layout, isMobile, selectedMenus, selectedKeys, openKeys, handleOpenKeys, handleSelectedKeys, handleMenuSelect } = useLayoutState()
const menuTheme = computed(() => {
  if (theme.value === 'inverted')
    return 'dark'
  return theme.value
})
</script>

<template>
  <a-menu
  class="ant-pro-sider-menu header-menu-responsive modern-sider-menu"
    :selected-keys="selectedKeys"
    :open-keys="collapsed ? [] : openKeys"
    :mode="(layout === 'top' && !isMobile) ? 'horizontal' : 'inline'"
    :theme="menuTheme"
    :collapsed="collapsed"
    @update:open-keys="handleOpenKeys"
    @update:selected-keys="handleSelectedKeys"
    @select="handleMenuSelect"
  >
    <template v-for="item in selectedMenus">
      <template v-if="!item.hideInMenu">
        <SubMenu 
        style="position: relative; top: 5px;"        :key="item.path" :item="item" />
      </template>
    </template>
  </a-menu>
</template>

<style scoped lang="less">
.modern-sider-menu {
  background: #ffffff;
  font-size: 16px;
  color: #111;
  border: none;
  padding: 0;

  :deep(.ant-menu-inline) {
    border-inline-end: none;
  }

  :deep(.ant-menu-item),
  :deep(.ant-menu-submenu-title) {
    height: 42px;
    line-height: 42px;
    border-radius: 0;
    margin: 0;
    padding-inline: 16px !important;
    background: transparent;
    transition: none;

    &:hover {
      color: #111;
      background: transparent;
    }
  }

  :deep(.ant-menu-item::after) {
    display: none;
  }

  :deep(.ant-menu-item-selected),
  :deep(.ant-menu-item-selected.ant-menu-item-only-child),
  :deep(.ant-menu-item.ant-menu-item-selected),
  :deep(.ant-menu-item.ant-menu-item-selected.ant-menu-item-only-child) {
    color: #000 !important;
    font-weight: 600 !important;
    background: transparent !important;
    background-color: transparent !important;
    box-shadow: none !important;
  }

  :deep(.ant-menu-item-selected::before),
  :deep(.ant-menu-item-selected::after) {
    display: none !important;
  }

  :deep(.ant-menu-item-selected a),
  :deep(.ant-menu-inline .ant-menu-item-selected .ant-menu-title-content),
  :deep(.ant-menu-item-selected .ant-menu-title-content) {
    color: #000 !important;
  }

  :deep(.ant-menu-submenu-selected > .ant-menu-submenu-title) {
    color: #000 !important;
    font-weight: 600;
    background: transparent !important;
    background-color: transparent !important;
  }

  :deep(.ant-menu-submenu-open > .ant-menu-submenu-title) {
    color: #000;
    font-weight: 600;
    background: transparent !important;
    background-color: transparent !important;
  }

  :deep(.ant-menu-item a) {
    color: inherit;
  }

  :deep(.ant-menu:not(.ant-menu-horizontal) .ant-menu-item-selected),
  :deep(.ant-menu:not(.ant-menu-horizontal) .ant-menu-item-selected.ant-menu-item-only-child) {
    background-color: transparent !important;
    background: transparent !important;
  }
}
</style>
